Skip to content

Conversation

@dvdchr
Copy link
Contributor

@dvdchr dvdchr commented Nov 6, 2023

Hi @momo-ozawa and @hassaanelgarem 👋🏼 , I'm assigning y'all as reviewers based on GitHub recommendations.

Some of the unit test cases failed locally because the assertions expected the code to use , as the thousands separator and . as the decimal separator. However, in my locale en_ID, it is the other way around (e.g. 10.000, 1,25M).

This PR addresses the issue by using the abbreviatedString(forHeroNumber:) for the expected value so it adjusts properly in different locales.

Alternatively, we can also force all local test runs to run in the UTC timezone and use en_US locale, but I'm not sure if this is the best way. 🤔 cc-ing @mokagio in case you have thoughts on this.

To test

  • Go to WordPressUnitTests.xctestplan > Configuration.
  • In the Localization > Application Region field, select Indonesia.
  • 🔎 Run DashboardStatsViewModelTests.testReturnedDataIsFormattedCorrectly() and BlazeCampaignViewModelTests.testViewModel() and verify that they are passing.
  • 🔎 Re-run the tests in your local region, and ensure that they are also passing.

Regression Notes

  1. Potential unintended areas of impact
    Should be none.

  2. What I did to test those areas of impact (or what existing automated tests I relied on)
    Ran the tests in both local and US locale.

  3. What automated tests I added (or what prevented me from doing so)
    N/A.

PR submission checklist:

  • I have completed the Regression Notes.
  • I have considered adding unit tests for my changes.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

UI Changes testing checklist:

Not applicable.

  • Portrait and landscape orientations.
  • Light and dark modes.
  • Fonts: Larger, smaller and bold text.
  • High contrast.
  • VoiceOver.
  • Languages with large words or with letters/accents not frequently used in English.
  • Right-to-left languages. (Even if translation isn’t complete, formatting should still respect the right-to-left layout)
  • iPhone and iPad.
  • Multi-tasking: Split view and Slide over. (iPad)

@dvdchr dvdchr added [Type] Enhancement Testing Unit and UI Tests and Tooling Not User Facing labels Nov 6, 2023
@dvdchr dvdchr added this to the 23.7 milestone Nov 6, 2023
@wpmobilebot
Copy link
Contributor

WordPress Alpha📲 You can test the changes from this Pull Request in WordPress Alpha by scanning the QR code below to install the corresponding build.
App NameWordPress Alpha WordPress Alpha
ConfigurationRelease-Alpha
Build Numberpr21982-e0240de
Version23.6
Bundle IDorg.wordpress.alpha
Commite0240de
App Center BuildWPiOS - One-Offs #7720
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@wpmobilebot
Copy link
Contributor

Jetpack Alpha📲 You can test the changes from this Pull Request in Jetpack Alpha by scanning the QR code below to install the corresponding build.
App NameJetpack Alpha Jetpack Alpha
ConfigurationRelease-Alpha
Build Numberpr21982-e0240de
Version23.6
Bundle IDcom.jetpack.alpha
Commite0240de
App Center Buildjetpack-installable-builds #6736
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@momo-ozawa
Copy link
Contributor

Thanks for addressing this!


// Then stats are displayed
XCTAssertEqual(viewModel.impressions, "1,000")
XCTAssertEqual(viewModel.impressions, 1_000.abbreviatedString())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into this @dvdchr.

By calling abbreviatedString() here, it seems like we are testing more at the implementation level than the behavior level. That is, reading the test one doesn't learn what the expected impressions value, only that it should be whatever abbreviatedString() returns.

For reference, here's the production code, which, unsurprisingly, calls abbreviatedString():

self.impressions = campaign.stats?.impressionsTotal?.abbreviatedString() ?? "0"

This is probably okay practically, because we are not likely are we to change this formatting...

Still, I think we would be better served by making the application language and region deterministic, as you suggested in the PR description.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still, I think we would be better served by making the application language and region deterministic, as you suggested in the PR description.

Plus 1 on this. While this fixes tests for Indonesian, I tried running DashboardStatsViewModelTests with Arabic as the locale, and it still failed.

@dvdchr
Copy link
Contributor Author

dvdchr commented Nov 10, 2023

Hey, a quick update. As per @mokagio and @hassaanelgarem 's inputs, I tried updating the WordPressUnitTests.xctestplan configuration to use the English language and United States as the location but found additional new tests failing under this setting.

Unfortunately, I'll need to put this on hold this week as I need to wrap up my project work. I'll take another look at my downtime during the meetup. In the meantime, I'll clear the milestone target and set this to Draft for now.

@dvdchr dvdchr marked this pull request as draft November 10, 2023 11:47
@dvdchr dvdchr removed this from the 23.7 milestone Nov 10, 2023
@hassaanelgarem hassaanelgarem removed their request for review November 12, 2023 13:07
@mokagio
Copy link
Contributor

mokagio commented Nov 14, 2023

Thank you for the update @dvdchr

@dvdchr dvdchr added this to the Someday milestone Apr 30, 2024
@kean kean closed this Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Testing Unit and UI Tests and Tooling [Type] Enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants